package cn.edu.nsmc.modules.sys.dao;

import cn.edu.nsmc.common.utils.R;
import cn.edu.nsmc.modules.sys.entity.SysWorksheetRecord;
import cn.edu.nsmc.modules.sys.entity.form.MaintenanceDataForm;
import cn.edu.nsmc.modules.sys.entity.vo.MaintenanceDataRecordVo;
import cn.edu.nsmc.modules.sys.entity.vo.MaintenanceDataRepairmanVo;
import cn.edu.nsmc.modules.sys.entity.vo.SysUserVO;
import cn.edu.nsmc.modules.sys.entity.vo.SysWorksheetRecordVo;
import cn.edu.nsmc.modules.sys.form.req.ReqWorkSheetListBody;
import cn.edu.nsmc.modules.sys.form.req.WorksheetRecordExcel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface SysWorksheetRecordDao extends BaseMapper<SysWorksheetRecord> {

    List<SysWorksheetRecord> wxList(@Param("userId") Long userId);

    List<WorksheetRecordExcel> export(Integer page,Integer size,@Param("p") ReqWorkSheetListBody worksheetRecordExcel);

    List<SysWorksheetRecordVo> getList(Integer page, Integer size, SysWorksheetRecord sysWorksheetRecord);

    Integer getNumber(SysWorksheetRecord sysWorksheetRecord);

    @Update("update sys_worksheet_record set admin_note=#{note} where id=#{id}")
    Integer commentWorksheet(Long id, String note);

    Integer auditWorksheet(List<Long> ids, Integer auditType, String cause);

    Integer getMaintenanceRepairmanNumber(MaintenanceDataForm maintenanceDataForm);

    List<MaintenanceDataRepairmanVo> getMaintenanceRepairmanList(Integer page, Integer size, MaintenanceDataForm maintenanceDataForm);

    List<MaintenanceDataRecordVo> getMaintenanceExcel(MaintenanceDataForm maintenanceDataForm);

    @MapKey("statusCount")
    List<Map<String, Object>> getStatusCount(MaintenanceDataForm maintenanceDataForm);

    @MapKey("typeCount")
    List<Map<String, Object>> getTypeCount(MaintenanceDataForm maintenanceDataForm);

    List<MaintenanceDataRecordVo> getMaintenanceRecordList(Integer page, Integer size, MaintenanceDataForm maintenanceDataForm);

    Integer getMaintenanceRecordNumber(MaintenanceDataForm maintenanceDataForm);

    @Insert("insert into sys_worksheet_record (applicant_id, auditor_id, audit_status, worksheet_type, cause, memo, file_path, repairman_id, apply_time, start_time, end_time, priority, reply_info, admin_note) " +
            "values (#{appllicatId},#{auditorId},#{auditStatus},#{worksheetType},#{cause},#{memo},#{filePath},#{repairmanId},#{applyTime},#{startTime},#{endTime},#{priority},#{replyInfo},#{adminNote})")
    R addRecordByAdmin(SysWorksheetRecord sysWorksheetRecord);

    @MapKey("id")
    List<Map<String, Object>> worksheetCntLeft(Date startTime, Date endTime, Integer queryType);

    @MapKey("id")
    List<Map<String, Object>> worksheetCntRight(Date startTime, Date endTime,Integer spanType,Integer queryType);

    Integer countExport(@Param("p") ReqWorkSheetListBody listBody);
}
